package pers.muci.oauthserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * ClassName: AccessTokenConfig
 * Description:
 * date: 2021/10/11 16:28
 *
 * @author muci
 * @since JDK 1.8
 */
@Configuration
public class AccessTokenConfig {
    /**
     * 指定 Token 的存储方式
     * 此处设置存在内存中
     * TokenStore 有五个实现类
     *      InMemoryTokenStore：系统默认，内存存储模式，单机模式下应用，分布式不推荐
     *      JdbcTokenStore：数据库保存模式
     *      JwtTokenStore：无状态登陆，主流使用
     *      RedisTokenStore：redis存储，主流使用
     *      JwkTokenStore：JSON Web Key保存 token
     * @return
     */
   /*
    @Bean
    TokenStore tokenStore(){
        return new InMemoryTokenStore();
    }*/

    @Autowired
    RedisConnectionFactory redisConnectionFactory;

    @Bean
    TokenStore redisTokenStore(){
        return new RedisTokenStore(redisConnectionFactory);
    }
}
